package com.project.server.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.project.server.model.Order;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.time.LocalDateTime;

@Mapper
public interface OrderMapper extends BaseMapper<Order> {
    
    @Select("SELECT COALESCE(SUM(total_amount), 0) FROM orders WHERE restaurant_id = #{restaurantId} AND create_time BETWEEN #{start} AND #{end}")
    BigDecimal getTotalRevenue(@Param("restaurantId") Long restaurantId, @Param("start") LocalDateTime start, @Param("end") LocalDateTime end);
    
    @Select("SELECT COUNT(*) FROM orders WHERE restaurant_id = #{restaurantId} AND create_time BETWEEN #{start} AND #{end}")
    Integer getOrderCount(@Param("restaurantId") Long restaurantId, @Param("start") LocalDateTime start, @Param("end") LocalDateTime end);
    
    @Select("SELECT COUNT(DISTINCT user_id) FROM orders WHERE restaurant_id = #{restaurantId} AND create_time BETWEEN #{start} AND #{end}")
    Integer getCustomerCount(@Param("restaurantId") Long restaurantId, @Param("start") LocalDateTime start, @Param("end") LocalDateTime end);

    @Select("SELECT COUNT(*) FROM orders WHERE restaurant_id = #{restaurantId} AND status = 3 AND create_time BETWEEN #{start} AND #{end}")
    Integer getCompletedOrderCount(@Param("restaurantId") Long restaurantId, @Param("start") LocalDateTime start, @Param("end") LocalDateTime end);

    @Select("SELECT COUNT(*) FROM orders WHERE restaurant_id = #{restaurantId} AND status = 2 AND create_time BETWEEN #{start} AND #{end}")
    Integer getCanceledOrderCount(@Param("restaurantId") Long restaurantId, @Param("start") LocalDateTime start, @Param("end") LocalDateTime end);
} 